package com.ruoyi.activity.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.activity.domain.TbLotteryActivity;
import com.ruoyi.activity.service.ITbLotteryActivityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 抽奖Controller
 *
 * @author ruoyi
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/activity")
public class TbLotteryActivityController extends BaseController {
    @Autowired
    private ITbLotteryActivityService tbLotteryActivityService;

    /**
     * 查询抽奖列表
     */
    @RequiresPermissions("activity:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(TbLotteryActivity tbLotteryActivity) {
        startPage();
        List<TbLotteryActivity> list = tbLotteryActivityService.selectTbLotteryActivityList(tbLotteryActivity);
        return getDataTable(list);
    }

    /**
     * 导出抽奖列表
     */
    @RequiresPermissions("activity:activity:export")
    @Log(title = "抽奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLotteryActivity tbLotteryActivity) {
        List<TbLotteryActivity> list = tbLotteryActivityService.selectTbLotteryActivityList(tbLotteryActivity);
        ExcelUtil<TbLotteryActivity> util = new ExcelUtil<TbLotteryActivity>(TbLotteryActivity.class);
        util.exportExcel(response, list, "抽奖数据");
    }

    /**
     * 获取抽奖详细信息
     */
    @RequiresPermissions("activity:activity:query")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Integer activityId) {
        return success(tbLotteryActivityService.selectTbLotteryActivityByActivityId(activityId));
    }

    /**
     * 新增抽奖
     */
    @RequiresPermissions("activity:activity:add")
    @Log(title = "抽奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLotteryActivity tbLotteryActivity) {
        return toAjax(tbLotteryActivityService.insertTbLotteryActivity(tbLotteryActivity));
    }

    /**
     * 修改抽奖
     */
    @RequiresPermissions("activity:activity:edit")
    @Log(title = "抽奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLotteryActivity tbLotteryActivity) {
        return toAjax(tbLotteryActivityService.updateTbLotteryActivity(tbLotteryActivity));
    }

    /**
     * 删除抽奖
     */
    @RequiresPermissions("activity:activity:remove")
    @Log(title = "抽奖", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Integer[] activityIds) {
        return toAjax(tbLotteryActivityService.deleteTbLotteryActivityByActivityIds(activityIds));
    }
}
